package com.xsy.android.compose.wandroid.ui.page.project.view

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ScrollableTabRow
import androidx.compose.material3.Tab
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.xsy.android.compose.wandroid.logic.model.ClassifyModel
import com.xsy.android.compose.wandroid.logic.utils.getHtmlText

@Composable
fun ArticleTabRow(
    modifier: Modifier = Modifier,
    position: Int?,
    data: List<ClassifyModel>,
    onTabCLick: (Int, Int, Boolean) -> Unit
) {
    ScrollableTabRow(
        selectedTabIndex = position ?: 0,
        modifier = modifier
            .wrapContentWidth()
            .background(color = MaterialTheme.colorScheme.primary),
        edgePadding = 3.dp
    ) {
        data.forEachIndexed { index, classifyModel ->
            Tab(
                text = { Text(text = getHtmlText(classifyModel.name)) },
                selected = position == index,
                onClick = {
                    onTabCLick(index, classifyModel.id, false)
                }
            )
        }
        onTabCLick(0, data[position ?: 0].id, true)
    }
}